<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>4班抽卡</title>
    <style>
        body{
            background-color: #FFE0E6;
        }
        #tab{
            height:250px;
            width: 800px;
            margin:0px auto;
            margin-top: 10px;
            border-spacing: 15px;
        }
        #tab td{
            border: solid 3px #FF5072;
            width: 100px;
            height: 50px;
            text-align: center;
            font-weight: bold;
            background-color: white;
        }
        #btn{
            text-align: center; 
            margin-top: 10px;
        }
        .btn1{
            width: 150px;
            height: 50px;
            font-size: large;
            color: white;
            background-color: #FF5072;
            border: 0px;
        }
        .btn1:hover{
            background-color: white;
            color: #FF5072;
            border: 4px #FF5072 solid;
        }
    </style>
</head>
<body>
    <script>
        var itv,randNum,times = 0;

        function fn(){
            times++;
            var rand = parseInt(Math.random()*2);
            rand == 0 ? randNum = parseInt(Math.random()*8+1) : randNum = Math.ceil(Math.random()*33+9)

            var randId = document.getElementById('td'+randNum);
            console.log(randId);
            //清空颜色
            for (let i = 1; i <= 42; i++) {
                var clearNum = document.getElementById('td'+i);
                clearNum.style.backgroundColor = 'white';
                randId.style.color = 'black';
            }
            randId.style.backgroundColor = '#FF5072';
            //结束
            if (times > 30) {
                randId.style.color = 'white';
                document.getElementById('pOutput').innerText = '掌声有请：'+randId.innerText;
                clearInterval(itv);
            }
        }

        function start(){
            for (let i = 1; i <= 42; i++) {
                var clearNum = document.getElementById('td'+i);
                clearNum.style.backgroundColor = 'white';
                clearNum.style.color = 'black';
            }
            times = 0;
            document.getElementById('pOutput').innerText = '下一位男/女嘉宾是...';
            itv = setInterval(fn,80);
        }
    </script>
    
    <div>
        <h1 style="text-align:center;color: #FF5072;">软件4班全明星</h3>
        <table id="tab">
            <tr>
                <td id="td1">郑玮喆</td>
                <td id="td2">庄云</td>
                <td id="td3">廖治先</td>
                <td id="td4">郑文源</td>
                <td id="td5">戴俊锋</td>
                <td id="td6">陈昊童</td>
            </tr>
            <tr>
                <td id="td7">谢金金</td>
                <td id="td8">占志新</td>
                <td id="td9">张淑芳</td>
                <td id="td10">刘永潘</td>
                <td id="td11">廖柏成</td>
                <td id="td12">郑宗帅</td>
            </tr>
            <tr>
                <td id="td13">李韦峰</td>
                <td id="td14">吴欣燕</td>
                <td id="td15">陈梅香</td>
                <td id="td16">陈立智</td>
                <td id="td17">袁贵森</td>
                <td id="td18">赵浩敏</td>
            </tr>
            <tr>
                <td id="td19">林世涛</td>
                <td id="td20">罗启恒</td>
                <td id="td21">卢国建</td>
                <td id="td22">黄柱菘</td>
                <td id="td23">陈鹏</td>
                <td id="td24">张耀仁</td>
            </tr>
            <tr>
                <td id="td25">陈华伟</td>
                <td id="td26">张正豪</td>
                <td id="td27">韦仲晓</td>
                <td id="td28">黄富贵</td>
                <td id="td29">陆建锋</td>
                <td id="td30">曾德森</td>
            </tr>
            <tr>
                <td id="td31">吴文龙</td>
                <td id="td32">陆利群</td>
                <td id="td33">黄雄</td>
                <td id="td34">王世财</td>
                <td id="td35">张先杰</td>
                <td id="td36">胡基耀</td>
            </tr>
            <tr>
                <td id="td37">马鑫涛</td>
                <td id="td38">李涛</td>
                <td id="td39">杨凌翔</td>
                <td id="td40">罗此东</td>
                <td id="td41">唐皓颖</td>
                <td id="td42">白婉婷</td>
            </tr>

        </table>
        <div id="btn">
            <button onclick="start()" class="btn1">单次寻访</button>
            <p id="pOutput"></p>
        </div>

    </div>

</body>
</html>